package com.example.myservlet;

import com.example.anno.RequestMapping;
import com.example.liteflow.StartNode;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.slot.DefaultContext;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequestMapping("/liteflow")
public class LiteflowTestServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
        test1();
    }

    private void test1() {
        //启动解读：https://developer.volcengine.com/articles/7392432442763640871
        //文档，可惜声明式组件只能在springboot环境中使用 https://liteflow.cc/pages/46f0fa/
        LiteflowConfig config = new LiteflowConfig();
        config.setRuleSource("classpath:liteflow/test.xml");
        FlowExecutor flowExecutor = FlowExecutorHolder.loadInstance(config);

        DefaultContext defaultContext = new DefaultContext();
        defaultContext.setData("name", "aaaa");
        defaultContext.setData("age", 1000);
        LiteflowResponse sampleChain = flowExecutor.execute2Resp("sampleChain", "", defaultContext);
        log.info(sampleChain.toString());
    }

}